package cn.by.wms.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.by.wms.entity.*;
import cn.by.wms.dao.ShelfDao;
import cn.by.wms.service.ShelfService;

import java.util.List;

/**
 * 货架;(206_shelf)表服务实现类
 * @author : heimi
 * @date : 2024-11-22
 */
@Service
public class ShelfService {

    @Autowired
    private ShelfDao shelfDao;

    public List<Shelf> select(ShelfQuery query) {
        LambdaQueryWrapper<Shelf> wapper =new  LambdaQueryWrapper();
        wapper.eq(query.getId() != null, Shelf::getId, query.getId() );
        wapper.like(query.getName() != null, Shelf::getName, query.getName() );
        wapper.eq(query.getWarehouselId()!= null, Shelf::getWarehouselId, query.getWarehouselId());
        wapper.eq(query.getStatus() != null, Shelf::getStatus, query.getStatus());
        return shelfDao.selectList(wapper);
    }

    public Integer insert(Shelf shelf) {
        return shelfDao.insert(shelf);
    }

    public List<WarehouseAndShelf> selectAll() {
        return shelfDao.selectAll();
    }

    public Integer update(Shelf shelf) {
        LambdaUpdateWrapper<Shelf> updateWrapper =new  LambdaUpdateWrapper();
        updateWrapper.eq(Shelf::getId, shelf.getId());
        updateWrapper.set(shelf.getName() != null, Shelf::getName, shelf.getName() );
        updateWrapper.set(shelf.getSeq() != null, Shelf::getSeq, shelf.getSeq() );
        updateWrapper.set(shelf.getWarehouselId()!=null,Shelf::getWarehouselId , shelf.getWarehouselId());
        updateWrapper.set(shelf.getBrief()!=null, Shelf::getBrief,shelf.getBrief());
        updateWrapper.set(shelf.getStatus()!=null, Shelf::getStatus , shelf.getStatus());

        return shelfDao.update(updateWrapper);
    }

    public Integer delete(Integer id) {

        return shelfDao.deleteById(id);
    }


}